<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Jedrzej\Pimpable\PimpableTrait;

class SystemGroup extends Model
{
    use HasFactory;
    use PimpableTrait;

    public $searchable = [
        'name',
        'info',
        'config_name',
    ];

    public $fillable = [
        'name',
        'info',
        'config_name',
        'fields'
    ];

    public $casts = [
        'fields' => 'array',
    ];

    public $sortable = [
        'name',
    ];

    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 组合数据表所属商品分类
     */
    public function category()
    {
        return $this->belongsTo(Category1::class, 'category_id','id');
    }

    /**
     * 组合数据表下的所有数据
     */
    public function systemGroupData()
    {
        return $this->hasMany(SystemGroupData::class, 'group_id','id');
    }
}
